/**
@file chou.cpp
@brief Chou class methods implementation

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 3 of the License.

@author VestniK (Sergey N.Vidyuk)
 */
#include "chou.h"

#include "defaults.h"

using namespace mjn;

bool Chou::isValid() const {
   // Test correct number of tiles in combination
   if ( tiles.size() != CombinationSize ) {
      return false;
   }
   // Test that combination contain only numbered tiles
   foreach ( Tile t,tiles ) {
      if ( (t.getSuit() != Tile::Dot)&&(t.getSuit() != Tile::Bamboo)&&(t.getSuit() != Tile::Character)  ) {
         return false;
      }
   }
   // Test that all tiles different but have the same type
   for ( int i = 0; i<tiles.size()-1; i++ ) {
      for ( int j = i+1; j<tiles.size(); j++ ) {
         if ( tiles[i] == tiles[j] ) {
            return false;
         }
         if ( tiles[i].getSuit() != tiles[j].getSuit() ) {
            return false;
         }
      }
   }
   // Searching maximum and minimum tile number
   int max = MIN_TILE_NUMBER - 1;
   int min = MAX_TILE_NUMBER + 1;
   foreach ( Tile t,tiles ) {
      if ( (int)t.getRank() < min ) {
         min = (int)t.getRank();
      }
      if ( (int)t.getRank() > max ) {
         max = (int)t.getRank();
      }
   }
   if ( (max - min) != 2 ) {
      return false;
   }
   return true;
}

unsigned Chou::calculateScore(WindType roundWind,WindType playerWind) const {
   return 0;
}

unsigned Chou::calculateMultiplyFactor(WindType roundWind,WindType playerWind) const {
   return 1;
}
